<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('任务完成')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-select-css" />
    <th:block th:include="include :: summernote-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-task-result-edit">
        <div class="col-md-12">
            <div class="form-group">
                <label class="col-sm-2 control-label">任务标题：</label>
                <div class="col-sm-9">
                    <input type="text" required maxlength="50" th:field="*{task.taskTitle}"  class="form-control" readonly>
                    <input th:id="file" th:value="${task.taskId}" th:field="*{task.taskId}" type="hidden"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">紧急程度：</label>
                <div class="col-sm-9">
                    <th:block th:if="*{task.priority}==1">
                        <input type="text" required maxlength="50"  value="紧急"  class="form-control" readonly>
                    </th:block>
                    <th:block th:if="*{task.priority}==2">
                        <input type="text" required maxlength="50"  value="非常紧急"  class="form-control" readonly>
                    </th:block>
                    <th:block th:if="*{task.priority}==0">
                        <input type="text" required maxlength="50"  value="普通"  class="form-control" readonly>
                    </th:block>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">执行人员：</label>
                <div class="col-sm-9">
                    <input type="text" required maxlength="50" th:field="*{task.userName}"  class="form-control" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">任务时间：</label>
                <div class="col-sm-9">
                    <div class="input-daterange input-group">
                        <input type="text" class="input-sm form-control" th:field="*{task.starttime}" placeholder="开始时间" readonly>
                        <span class="input-group-addon">-</span>
                        <input type="text" class="input-sm form-control" placeholder="结束时间" th:field="*{task.endtime}" readonly>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">创建时间：</label>
                <div class="col-sm-9">
                    <input type="text" class="input-sm form-control" th:field="*{task.createtime}" placeholder="创建时间" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">任务状态：</label>
                <div class="col-sm-9">
                    <th:block th:if="*{task.status}==1">
                        <input type="text" required maxlength="50"  value="已完成"  class="form-control" readonly>
                    </th:block>
                    <th:block th:if="*{task.status}==2">
                        <input type="text" required maxlength="50"  value="未完成"  class="form-control" readonly>
                    </th:block>
                    <th:block th:if="*{task.status}==0">
                        <input type="text" required maxlength="50"  value="已放弃"  class="form-control" readonly>
                    </th:block>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">任务内容：</label>
                <div class="col-sm-9">
                    <textarea type="text" style="height: 100px" multiple th:field="*{task.content}" class="form-control" placeholder="请输入任务内容" readonly></textarea>
                </div>
            </div>
<hr/>
            <div class="form-group">
                <label class="col-sm-2 control-label">上传文件：</label>
                <div class="col-sm-9 ">
                    <input id="filePath" name="file" type="file" multiple th:text="'原文件名：'+${task.result.resultFile}" th:value="${task.result.resultFile}" th:field="*{task.result.resultFile}" class="file-upload form-control " />
                    <input th:id="file" th:value="${task.result.resultFile}" type="hidden"/><input th:id="fileName" th:value="${task.result.resultFileName}" type="hidden"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">工作成果描述：</label>
                <div class="col-sm-9">
                    <textarea type="text" style="height: 100px" multiple th:field="*{task.result.desc}" class="form-control" placeholder="请输入任务内容" maxlength="255"></textarea>
                    <input th:id="resultId" th:value="${task.result.resultId}" type="hidden"/>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: summernote-js" />
<th:block th:include="include :: bootstrap-fileinput-js" />
<script type="text/javascript">
    var prefix = ctx + "system/task/result";
    var fileName="";
    var url="";
    var file="";

    // 上传文件
    function uploadFile() {
        var formData = new FormData();
        if ($('#filePath')[0].files[0] == null) {
            return false;
        }
        file = $('#filePath')[0].files[0].name;
        formData.append('fileName', $("#fileName").val());
        formData.append('file', $('#filePath')[0].files[0]);
        $.ajax({
            url: ctx + "common/upload",
            type: 'post',
            cache: false,
            async: false,
            data: formData,
            processData: false,
            contentType: false,
            dataType: "json",
            success: function(result) {
                fileName = result.fileName;
                url = result.url;
                if (result) {
                    parent.$.modal.msgSuccess(result.msg);
                }
            },
            error: function(error) {
                $.modal.alertWarning("图片上传失败。");
            }
        });
    }

    $("#form-task-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            uploadFile();
            var resultId = $("#resultId").val();
            var val = $('#form-task-result-edit').serialize();
            $.operate.save(prefix + "/edit", val +"&result.resultId="+resultId+"&result.resultFile="+file+"&result.resultFileName="+fileName+"&result.resultUrl="+url);
        }
    }

</script>
</body>
</html>
